package com.example.leetdemo.finash;

public class Solution55 {
    public boolean canJump(int[] nums) {
        int[] dp = new int[nums.length];
        dp[0] = 1;
        for (int i = 0; i < nums.length; i++) {
            if (dp[i] == 0) {
                continue;
            }
            int a = nums[i];
            if (i + a + 1 >= nums.length) {
                return true;
            }
            for (int j = i + 1; j < Math.min(nums.length, i + a + 1); j++) {
                dp[j] = 1;
            }
        }
        return dp[nums.length - 1] > 0;
    }

    public static void main(String[] args) {
        Solution55 solution55 = new Solution55();
        System.err.println(solution55.canJump(new int[] {3,2,1,0,4}));
    }
}
